/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.csreason.service.impl;

import com.icinfo.cloud.provider.punish.csreason.mapper.CaseReasonContentMapper;
import com.icinfo.cloud.provider.punish.csreason.model.CaseReasonContent;
import com.icinfo.cloud.provider.punish.csreason.service.ICaseReasonContentService;
import com.icinfo.framework.core.service.support.MyBatisServiceSupport;
import com.icinfo.framework.mybatis.mapper.entity.Example;
import com.icinfo.framework.tools.utils.StringUtils;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 描述:  case_reason_content 对应的Service接口实现类.<br>
 *
 * @author framework generator
 * @date 2022年10月26日
 */
@Service
public class CaseReasonContentServiceImpl extends MyBatisServiceSupport implements ICaseReasonContentService {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(CaseReasonContentServiceImpl.class);

    @Resource
    private CaseReasonContentMapper caseReasonContentMapper;

    /**
     * 保存案由信息项
     * @param id 案由主键
     * @param list 信息列表
     * @param type 信息类型(1-违则 2-处罚事项)
     */
    @Override
    public void save(String id, List<String> list, String type) {
        if (StringUtils.isAnyBlank(id,type) || CollectionUtils.isEmpty(list)){
            return;
        }
        caseReasonContentMapper.save(id,list,type);
    }

    /**
     * 根据业务主键删除案由信息
     * @param id 主键
     * @param type 删除信息类型(1-违则 2-处罚事项 ''-全部删除)
     */
    @Override
    public void delete(String id, String type) {
        if (StringUtils.isBlank(id)){
            return;
        }
        Example example = new Example(CaseReasonContent.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("crId", id);
        if (StringUtils.isNotBlank(type)){
            criteria.andEqualTo("type", type);
        }
        caseReasonContentMapper.deleteByExample(example);
    }

    /**
     * 根据案由业务主键、类型查询对应案由信息项
     * @param id 业务主键
     * @param type 信息类型(1-违则 2-处罚事项 ''-查询全部)
     * @return List<String>
     */
    @Override
    public List<String> selectContentList(String id, String type) {
        if (StringUtils.isBlank(id)){
            return null;
        }
        return caseReasonContentMapper.selectContent(id,type);
    }
}
